<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/jsp/inc/header.jsp" %>
<c:set var="title" value="文章"/>
<c:set var="rootpath" value="${CONTEXT_PATH}/admin/article/article"/>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="${STATIC_HOST}/css/ligerui.css" rel="stylesheet" type="text/css"/>
    <link href="${STATIC_HOST}/css/common.css" rel="stylesheet" type="text/css" />
    <script src="${STATIC_HOST}/js/common.js" type="text/javascript"></script>
    <script src="${STATIC_HOST}/js/LG.js" type="text/javascript"></script>
    <title>${title}管理</title>
</head>
<body class="listbody">

	<!-- 导航开始 -->
	<div class="withicon">
		<span><b>当前位置：内容 &gt; <a href="list.do?view=${view}">${title}管理</a></b></span>
	</div>
	<!-- 导航结束 -->
	
	<!-- 搜索开始 -->
	<div id="mainsearch" class="l-panel">
		<div class="searchtitle l-panel-topbar"><span>搜索</span><img src="${STATIC_HOST}/images/common/searchtool.gif"><div class="togglebtn"></div></div>
		<div class="searchbox">
		<form action="${rootpath}/list.do" method="post" name="searchForm" id="searchForm">
		<ul>
		   <li class="li_search_left"><label for="eqId">文章id</label>：</li>
			   <li class="li_search_right">
			<input type="text" name="eqId" id="eqId" size="10" ltype='text' ligerui='{"width":100}'  value="${eqId}"/>
		  </li>
			<li class="li_search_left"><label for="eqChannelId">频道ID</label>：</li>
			<li class="li_search_right">
				<input type="text" name="eqChannelId" id="eqChannelId" size="10" ltype='text' ligerui='{"width":80}'  value="${eqChannelId}"/>
				<input value="..." type="button" class="l-button ellipsis"  onclick="f_select({'targetId':'eqChannelId','selectType':'/admin/site/channel','relatedName':'eqChannelId','relatedId':'eqChannelId'})">
			</li>
			<li class="li_search_left"><label for="eqColumnId">栏目ID</label>：</li>
			<li class="li_search_right">
				<input type="text" name="eqColumnId" id="eqColumnId" size="10" ltype='text' ligerui='{"width":80}'  value="${eqColumnId}"/>
				<input value="..." type="button" class="l-button ellipsis"  onclick="f_select({'targetId':'eqColumnId','selectType':'/admin/site/column'})">
			</li>
			<li class="li_search_left"><label for="eqSlaveFlag">显示栏目</label>：</li>
			<li class="li_search_right">
				<select name="eqSlaveFlag" id="eqSlaveFlag" ltype="select" size="1" ligerui='{"width":100}'>
					<option value="0"  <c:if test="${eqSlaveFlag==0}">selected</c:if> >只显示主栏目</option>
					<option value="1"  <c:if test="${eqSlaveFlag==1}">selected</c:if> >只显示从栏目</option>
					<option value=""  <c:if test="${eqSlaveFlag==''}">selected</c:if> >显示全部</option>
				</select>
			</li>

		  <div style="clear:both; padding-top:10px; display:none" id="advsearchdiv"><!--更多搜索开始-->
			  <li class="li_search_left"><label for="eqPublishStatus">发布状态</label>：</li>
			  <li class="li_search_right">
				  <select name="eqPublishStatus" id="eqPublishStatus" ltype="select" size="1" ligerui='{"width":100}'>
					  <option value=""  <c:if test="${eqPublishStatus==''}">selected</c:if> >-全部-</option>
					  <option value="0"  <c:if test="${eqPublishStatus==0}">selected</c:if> >未发布</option>
					  <option value="1"  <c:if test="${eqPublishStatus==1}">selected</c:if> >人工发布</option>
					  <option value="2"  <c:if test="${eqPublishStatus==2}">selected</c:if> >采集发布</option>
					  <option value="4"  <c:if test="${eqPublishStatus==4}">selected</c:if> >已撤稿</option>
				  </select>
			  </li>
			<li style="clear:both; padding-top:10px;"></li><!--换行-->
		  </div><!--更多搜索结束-->

		<li class="li_searchbutton">
		  <div id="searchbutton" class="button button2 buttonnoicon">
			<div class="button-l"></div>
			<div class="button-r"></div>
			<span>搜索</span>
		  </div>
		  <div class="div_advsearchbutton"></div>
		  <div id="advsearchbutton">
			<span>更多搜索</span>
		  </div>
		</li>
		</ul>
	  </form>
	  </div>
	</div>
	<!-- 搜索结束 -->   
	
	<div class="div_newline"></div>
	
	<!-- 列表开始 -->
	<div id="maingrid"></div> 
	<!-- 列表结束 -->
	
	<script type="text/javascript">
		//查看
		function show(id){
			jQuery("#view").val('/admin/article/article/show');
			submitReq("${rootpath}/show.do?id="+id);
		}
		//编辑
		function edit(id){
			jQuery("#view").val('');
			top.f_addTab(null, "编辑文章", "${rootpath}/edit.do?id="+id);
		}
		//新建
		function newObject(){
			jQuery("#view").val('');
			top.f_addTab(null, "新建文章", "${rootpath}/edit.do");
		}
		//获取选择ID
		function getSelectedId(){
			var selecteds = grid.getSelecteds();
			if (selecteds.length==0) { 
				return "";
			}
			var ids="";
			for(var key in selecteds){
				ids += (","+selecteds[key].id);
			}
			return ids.substring(1);
		}
		//撤稿
		function localDelelte(articleId, slaveFlag, columnId){
			var idAndslave = articleId+"_"+slaveFlag+"_"+columnId;
			$.ligerDialog.confirm('确定要批量撤稿吗？', function (yes) {
				if (yes) {
					showResult("${rootpath}/withdraw.do?idAndslave="+idAndslave);
				}
			});
		}
		//批量删除
		function batchDelete(){
			var selecteds = grid.getSelecteds();
			if (selecteds.length==0) {
				LG.tip('请选择要批量撤稿的行!');
				return "";
			}
			var idAndslave="";
			for(var key in selecteds){
				idAndslave += ((","+selecteds[key].articleId)+("_"+selecteds[key].slaveFlag)+("_"+selecteds[key].columnId));
			}
			if(idAndslave.length>0){
				idAndslave = idAndslave.substring(1);
			}
			$.ligerDialog.confirm('确定要批量撤稿吗？', function (yes) {
				if (yes) {
					showResult("${rootpath}/withdraw.do?idAndslave="+idAndslave);
				}
			});
		}
		function batchPublish() {
			var selecteds = grid.getSelecteds();
			if (selecteds.length==0) {
				LG.tip('请选择要批量发布的行!');
				return "";
			}
			var ids="";
			for(var key in selecteds){
				ids += (","+selecteds[key].id);
			}
			if(ids.length>0){
				ids = ids.substring(1);
			}
			$.ligerDialog.confirm('确定要批量发布吗？', function (yes) {
				if (yes) {
					showResult("${rootpath}/rePublish.do?ids="+ids);
				}
			});
		}
		function showResult(url){
			jQuery.getJSON(url,function(data){
				$.ligerDialog.alert(data.succs);
				grid.loadData();
			});
		}
		//无效
		function auditNotPass(){
			updateStatus( 0 );
		}
		//有效
		function auditPass(){
			updateStatus( 1 );
		}
		//更新状态
		function updateStatus(statusValue,id){
			var path = "${rootpath}/updateStatus.do?status="+statusValue;
			if( !isNaN(id) ){
				path += "&eqId=" + id;
			}else{
				var ids = getSelectedId();
				if (ids.length==0) { 
					LG.tip('请选择要更新的行!'); 
					return;
				}
				path += "&inIds=" + ids;
			}
			$.ligerDialog.confirm("确定要操作吗？", function (yes) {
				if( yes ) submitReq(path);
			});
		}
		//提交
		function submitReq(path,query,notsubmit){
			pageFormObj = document.pageForm;
			pageFormObj.action = path;
			if(query){
				pageFormObj.queryParam.value = query;
			}
			if(!notsubmit){
				pageFormObj.submit();
			}
			return false;
		}
		//推送到栏目
		function push2column(){
			push2("column");
		}
		//推送到区块
		function push2region(){
			push2("region");
		}

		function push2(type){
			var selecteds = grid.getSelecteds();
			if (selecteds.length==0) {
				LG.tip('请选择要批量推送的行!');
				return "";
			}
			f_select({'selectType':'/admin/site/'+type,'callback':'callback'+type,'customParam':'&eqStatus=1','gridMultiple':'1'});
		}

		function callbackregion(jsonData){
			callbackcolumn(jsonData,'region');
		}

		function callbackcolumn(jsonData,type){
			var typeName = type || "column";
			var data = JSON.parse(jsonData);
			var targetIds = "";
			for (i = 0; i < data.length; i++) {
				targetIds += ("," + data[i].id);
			}
			if (targetIds.length > 0) {
				targetIds = targetIds.substr(1);
			}

			var selecteds = grid.getSelecteds();
			var articleIds="";
			for(var key in selecteds){
				articleIds += (","+selecteds[key].articleId);
			}
			articleIds = articleIds.substring(1);

			jQuery.getJSON("${CONTEXT_PATH}/admin/article/article/push.do?type="+typeName+"&articleIds="+articleIds+"&targetIds="+targetIds,function(data){
				$.ligerDialog.alert("<li><b><i>成功推送:</i></b></li>文章id:"+articleIds+"<br/>目标id:"+targetIds+"<br/>", '批量推送的结果');
			});
		}

	var publishStatusMap=${jsonali:toJSONString(publishStatusMap)};
	//列表
	var grid = $("#maingrid").ligerGrid({
		
      columns: [
        { display:"文章id", name:"articleId", align: 'left', width: 80, type: 'int' },
	    { display:"标题", name:"title", align: 'left', width: 300, render: function (row) {
			return "<a title='"+row.title+"' href='"+row.articleUrl+"' target='_blank'>"+row.title+"</a>";
			}
	    },
	    { display:"短标题", name:"titleShort", align: 'left', width: 100, hide:true },
	    { display:"信息源", name:"sourceName", align: 'left', width: 100, hide:true },
	  	{ display:"频道-栏目", name:"channelId", align: 'left', width: 130, render: function(row){
		  		return row.mainChannel + " - " + row.mainColumn;
	  		}
	  	},
	  	{ display:"栏目标识", name:"slaveFlag", align: 'left', width: 80, render: function (row) {
	  			if(row.slaveFlag == 0){
					return "<span style='color:#e48230;'>主栏目</span>";
				}else {
					return "<span style='color:#327a2e;'>从栏目</span>";
				}
			}
	  	},
	    { display:"发布时间", name:"publishTime", align: 'left', width: 130 ,type: 'date' },
	  	{ display:"发布状态", name:"publishStatus", align: 'left', width: 80, type: 'int', render: function(row){
		  		return "<span class='publishStatus" + row.publishStatus+"'>"+publishStatusMap[row.publishStatus]+"</span>";
	  		}
	  	},
        { display:"操作", minWidth: 150, isAllowHide: false, isSort: false, render: function(row){
            return '<img src="http://static.21cnimg.com/img/icons/content/edit.gif" class="imgbtn" alt="修改" title="修改" onclick="edit('+row.articleId+')" />'
              +'<img src="http://static.21cnimg.com/img/icons/content/delete2.gif" class="imgbtn" alt="撤稿" title="撤稿" onclick="localDelelte('+row.articleId+','+row.slaveFlag+','+row.columnId+')" />';
           }
         }
      ],
      parms: [
      		{name:'_ajax', value:1}  , { name:'eqSlaveFlag',value:'0'}
          <c:if test="${not empty eqId}">, { name:'eqId',value:'${eqId}'}</c:if>
          <c:if test="${not empty eqSiteId}">, { name:'eqSiteId',value:'${eqSiteId}'}</c:if>
          <c:if test="${not empty eqTitle}">, { name:'eqTitle',value:'${eqTitle}'}</c:if>
          <c:if test="${not empty eqTitleShort}">, { name:'eqTitleShort',value:'${eqTitleShort}'}</c:if>
          <c:if test="${not empty eqSummary}">, { name:'eqSummary',value:'${eqSummary}'}</c:if>
          <c:if test="${not empty eqKeyword}">, { name:'eqKeyword',value:'${eqKeyword}'}</c:if>
          <c:if test="${not empty eqSourceName}">, { name:'eqSourceName',value:'${eqSourceName}'}</c:if>
          <c:if test="${not empty eqAuthor}">, { name:'eqAuthor',value:'${eqAuthor}'}</c:if>
          <c:if test="${not empty eqFirstPicUrl}">, { name:'eqFirstPicUrl',value:'${eqFirstPicUrl}'}</c:if>
          <c:if test="${not empty eqArticleUrl}">, { name:'eqArticleUrl',value:'${eqArticleUrl}'}</c:if>
          <c:if test="${not empty eqArticleType}">, { name:'eqArticleType',value:'${eqArticleType}'}</c:if>
          <c:if test="${not empty eqPublishTime}">, { name:'eqPublishTime',value:'${eqPublishTime}'}</c:if>
          <c:if test="${not empty eqPublishStatus}">, { name:'eqPublishStatus',value:'${eqPublishStatus}'}</c:if>
          <c:if test="${not empty eqCreateUserId}">, { name:'eqCreateUserId',value:'${eqCreateUserId}'}</c:if>
          <c:if test="${not empty eqCreateTime}">, { name:'eqCreateTime',value:'${eqCreateTime}'}</c:if>
          <c:if test="${not empty eqModifyUserId}">, { name:'eqModifyUserId',value:'${eqModifyUserId}'}</c:if>
          <c:if test="${not empty eqModifyTime}">, { name:'eqModifyTime',value:'${eqModifyTime}'}</c:if>
          <c:if test="${not empty eqClickNum}">, { name:'eqClickNum',value:'${eqClickNum}'}</c:if>
          <c:if test="${not empty eqSummaryFlag}">, { name:'eqSummaryFlag',value:'${eqSummaryFlag}'}</c:if>
          <c:if test="${not empty eqReviewFlag}">, { name:'eqReviewFlag',value:'${eqReviewFlag}'}</c:if>
          <c:if test="${not empty eqPicFlag}">, { name:'eqPicFlag',value:'${eqPicFlag}'}</c:if>
         ] ,
		toolbar: { items: [
				{ line: true }
				,{ text: '推送栏目', click: push2column, img: 'http://static.21cnimg.com/img/icons/miniicons/list_extensions.gif' }
				,{ line: true }
				,{ text: '推送区块', click: push2region, img: 'http://static.21cnimg.com/img/icons/miniicons/list_extensions.gif' }
				,{ line: true }
				,{ text: '新增', click: newObject, img: 'http://static.21cnimg.com/img/icons/silkicons/add.png' }
				,{ line: true }
				,{ text: '撤稿', click: batchDelete, img: 'http://static.21cnimg.com/img/icons/silkicons/cross.png' }
				,{ line: true }
				,{ text: '发布', click: batchPublish, img: 'http://static.21cnimg.com/img/icons/silkicons/accept.png' }
				,{ line: true }
			] },
	    pageSize: ${pageSize}, pageSizeOptions:[5,10,20,40,60,80,100],
	    pageParmName:'pageNo', pagesizeParmName:'pageSize',
	    dataAction:'server', 
	    url: '${rootpath}/search.do',
	    rownumbers: true, checkbox: true, frozen: true , dateFormat:'yyyy-MM-dd hh:mm',
		width: '98%', height: '100%', rowHeight:25, fixedCellHeight: true, usePager: true
	});
	
	jQuery("#searchbutton").click(function(){
	    var params = '';
        var group = {};
		var form=$("#searchForm");
        $(":input", form).not(":submit, :reset, :image,:button, [disabled]").each(function (){
            if (!this.name) return;
            if ($(this).val() == null || $(this).val() == "") return;
            var ltype = $(this).attr("ltype");
            var optionsJSON = $(this).attr("ligerui"), options;
            if (optionsJSON){
                options = JSON2.parse(optionsJSON);
            }
            //get the value type(number or date)
            var value = $(this).val();
            var name = this.name;
            //如果是下拉框，那么读取下拉框关联的隐藏控件的值(ID值,常用与外表关联)
            if (ltype == "select" && options && options.valueFieldID){
                value = $("#" + options.valueFieldID).val();
                name = options.valueFieldID;
            }
            group[name]=value;
			params += ("&"+name+"="+encodeURIComponent(value));
        });
	    grid.set('parms', group);
        grid.loadData();
        $("#queryParam").val( params.substring(1) );
	});
	
	jQuery("#advsearchbutton").click(function(){
	    jQuery("#advsearchdiv").slideToggle('fast');
	});
	
	$("#eqStatus").val('${eqStatus}');//初始化下来菜单
	$("#searchForm").ligerForm();
	
	</script>
	
	<form action="${rootpath}/list.do" method="post"  name="pageForm" id="pageForm">
	  <input type="hidden" id="queryParam" name="queryParam" value="${queryParam}"/>
	  <input name="view" id="view" type="hidden" value="${view}"/>
	</form>
	<style>
		.publishStatus1{color: blue;}
		.publishStatus0{color: #8f8f8f;}
		.publishStatus2{color: green;}
		.publishStatus4{color: red;}
	</style>
	<%@ include file="/jsp/inc/footer.jsp"%>
</body>
</html>